Skip to content

[interop] Add support for importing and exporting declarations, as well as multi-file output #418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Aug 1, 2025

Conversation

nikeokoronkwo
Copy link
Collaborator

@nikeokoronkwo nikeokoronkwo commented Jul 17, 2025

Fixes #378
Fixes #387

This PR is for adding support for multiple file processing, with support for exporting and importing declarations even between files.

It makes use of a TransformManager which transforms various files and uses a ProgramMap to memoize and keep track of dependencies across files, which helps in reducing expensive transform calls to declarations already referenced from other files.
Rather than transforming every declaration in a source file, the type checker gets the declarations exported from the file, and processes those declarations and its dependencies only, making processing faster

The type checker helps to resolve types and imports, as well as resolve import declarations. Import declarations are not parsed by default so that we know we are only making use of imports actually referenced in code (which is helpful in single outputs for instance).

(The program map makes use of package:paths PathMap to easily work with paths for files and declarations, as the TS output may resolve either to a relative import in the file, or may reference the declaration externally as an absolute path).

Imported declarations are declared as ReferredTypes with a url property, which allows for referencing the normal

Exports are rewritten based on how they are specified, and are processed after transformation (since they are separate declarations and may be referenced as they are.

Imports are processed depending on the presence of the file:

  • If TS can find the file (i.e not global scope), then the declaration is referenced with the proper name as an import
  • If the file needed/imported is not included in the multi-file input params, then the declarations are generated in the output file as a single output.
  • If the declaration is in the global scope, then the generator can auto-generate these declarations as so.

# Conflicts:
#	web_generator/lib/src/interop_gen/transform/transformer.dart
#	web_generator/lib/src/js/typescript.types.dart
- added import support
- added gen of code inside file in the case of non multi-import
- added support for multiple file generation
- using `TransformManager` for managing transformation of code
@nikeokoronkwo nikeokoronkwo changed the title WIP: [interop] Add support for importing and exporting declarations, as well as multi-file output [interop] Add support for importing and exporting declarations, as well as multi-file output Jul 20, 2025
@nikeokoronkwo nikeokoronkwo marked this pull request as ready for review July 20, 2025 00:40
# Conflicts:
#	web_generator/lib/src/ast/declarations.dart
#	web_generator/lib/src/interop_gen/transform.dart
#	web_generator/lib/src/interop_gen/transform/transformer.dart
#	web_generator/lib/src/js/typescript.types.dart
@kevmoo kevmoo requested a review from srujzs July 21, 2025 22:19
@nikeokoronkwo nikeokoronkwo requested a review from srujzs July 23, 2025 21:57
@nikeokoronkwo nikeokoronkwo merged commit 1d5771b into dart-lang:main Aug 1, 2025
8 checks passed
@nikeokoronkwo nikeokoronkwo deleted the interop/import-export branch August 1, 2025 00:05
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Aug 4, 2025
…, web, webdriver

Revisions updated by `dart tools/rev_sdk_deps.dart`.

ai (https://github.com/dart-lang/ai/compare/7fbe88a..72a9283):
  72a9283  2025-07-31  Jacob MacDonald  add --exclude-tool option to exclude tools by name (dart-lang/ai#253)
  0dbbd8b  2025-07-30  Jacob MacDonald  only run in shell when on windows and running a .bat file (dart-lang/ai#252)
  0858b0b  2025-07-28  Jacob MacDonald  further prompt refinement, discourage use of temp ids and encourage getting the widget tree often (dart-lang/ai#249)
  912c1f3  2025-07-28  Jacob MacDonald  release dart_mcp v0.3.3 (dart-lang/ai#247)
  0f7cba8  2025-07-28  Jacob MacDonald  add analytics tracking for prompts (dart-lang/ai#246)

dartdoc (https://github.com/dart-lang/dartdoc/compare/882aea9..414953e):
  414953ed  2025-08-04  Sam Rawlins  Simplify how inheritance is computed. (dart-lang/dartdoc#4079)

ecosystem (https://github.com/dart-lang/ecosystem/compare/d5233c6..2fe3618):
  2fe3618  2025-08-01  dependabot[bot]  Bump the github-actions group with 3 updates (dart-lang/ecosystem#361)

protobuf (https://github.com/dart-lang/protobuf/compare/44ecd74..0b73b0d):
  0b73b0d  2025-07-30  Devon Carew  workspace, formatting, and proto version updates (google/protobuf.dart#1033)
  a664760  2025-07-30  Devon Carew  various CI workflow updates (google/protobuf.dart#1035)

test (https://github.com/dart-lang/test/compare/6aeb1e4..953e828):
  953e8282  2025-08-01  Nate Bosch  Drop executable arguments forwarding (dart-lang/test#2528)

tools (https://github.com/dart-lang/tools/compare/2a2a2d6..5e977d6):
  5e977d6f  2025-07-30  Jacob MacDonald  Fix mixtures of parentheses and spaces in windows command paths (dart-lang/tools#2138)
  607340ca  2025-07-29  Devon Carew  disable failing test (dart-lang/tools#2136)

vector_math (https://github.com/google/vector_math.dart/compare/13f185f..3939545):
  3939545  2025-08-04  Kevin Moore  Bump min SDK to 3.7, update dependencies, reformat (google/vector_math.dart#348)

web (https://github.com/dart-lang/web/compare/da1dd5d..1d5771b):
  1d5771b  2025-07-31  Nikechukwu  [interop] Add support for importing and exporting declarations, as well as multi-file output (dart-lang/web#418)

webdriver (https://github.com/google/webdriver.dart/compare/cfab787..595649d):
  595649d  2025-08-01  dependabot[bot]  Bump nanasess/setup-chromedriver (google/webdriver.dart#331)

Change-Id: Ia014bf6cafa9edcdaf453edda9cd5ecff516e16d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443625
Auto-Submit: Devon Carew <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Interop Gen: Support Import Declarations and Multi-File Output Interop Gen: Support Export/Import Declarations
2 participants